#define _CRT_SECURE_NO_WARNINGS	

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
typedef struct TreeNode TreeNode;

int postorder(TreeNode* root, int* sum)
{
    if (root == NULL)
        return 0;

    int left = postorder(root->left, sum);
    int right = postorder(root->right, sum);

    int gap = abs(left - right);
    *sum += gap;

    return left + right + root->val;
}

int findTilt(struct TreeNode* root)
{
    int sum = 0;
    postorder(root, &sum);
    return sum;
}